package com.yq.backend.service.impl;

import com.yq.backend.dto.CardDto;
import com.yq.backend.dto.winningListDto;
import com.yq.backend.dto.winningStatisticsDto;
import com.yq.backend.mapper.InfoManageMapper;
import com.yq.backend.pojo.Result;
import com.yq.backend.service.InfoManageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @descriptions: 信息管理
 * @author: yunqiang
 * @date: 2022/5/3 22:13
 */
@Slf4j
@Service
public class InfoManageServiceImpl implements InfoManageService {


    @Autowired
    private InfoManageMapper infoManageMapper;

    /**
     * 中奖统计
     * @param cardDto
     * @return
     */
    @Override
    public Result winningStatistics(CardDto cardDto) {
        int pageNow = cardDto.getPageNow();
        int pageSize = cardDto.getPageSize();
        if (pageNow > 0){
            pageNow  =(pageNow - 1)*pageSize;
        }else{
            pageNow = 0;
        }
        long total = infoManageMapper.winningStatisticsCount(cardDto);
        List<winningStatisticsDto> winningStatistics = infoManageMapper.winningStatistics(cardDto,pageNow,pageSize);
        if(CollectionUtils.isEmpty(winningStatistics)){
            return Result.noResult();
        }
        return Result.success(total,winningStatistics);
    }

    /**
     * 中奖列表
     * @param cardDto
     * @return
     */
    @Override
    public Result winningList(CardDto cardDto) {
        int pageNow = cardDto.getPageNow();
        int pageSize = cardDto.getPageSize();
        if (pageNow > 0){
            pageNow  =(pageNow - 1)*pageSize;
        }else{
            pageNow = 0;
        }
        long total = infoManageMapper.winningListCount(cardDto);
        List<winningListDto> winningListDtos = infoManageMapper.winningList(cardDto,pageNow,pageSize);
        if(CollectionUtils.isEmpty(winningListDtos)){
            return Result.noResult();
        }
        return Result.success(total,winningListDtos);
    }
}
